package org.dromara.common.upeport.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.dromara.common.core.utils.DateUtils;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.upeport.domain.UreportFileTbl;
import org.dromara.common.upeport.mapper.UreportFileTblMapper;
import org.dromara.common.upeport.service.IUreportFileTblService;
import org.dromara.common.web.core.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * 报表管理Service业务层处理
 *
 * @author yanshikui
 * @date 2022-10-07
 */
@Service
public class UreportFileTblServiceImpl extends BaseService implements IUreportFileTblService
{
    @Autowired
    private UreportFileTblMapper ureportFileTblMapper;

    /**
     * 查询报表管理
     *
     * @param id 报表管理主键
     * @return 报表管理
     */
    @Override
    public UreportFileTbl selectUreportFileTblById(Long id)
    {
        return ureportFileTblMapper.selectUreportFileTblById(id);
    }

    /**
     * 查询报表管理列表
     *
     *
     */
    @Override
    public Page<UreportFileTbl> selectUreportFileTblList(UreportFileTbl bo, PageQuery pageQuery)
    {
      LambdaQueryWrapper<UreportFileTbl> lqw = buildQueryWrapper(bo);

      Page<UreportFileTbl> result = ureportFileTblMapper.selectPage(pageQuery.build(), lqw);
        return result;
    }

    /**
     * 新增报表管理
     *
     * @param ureportFileTbl 报表管理
     * @return 结果
     */
    @Override
    public int insertUreportFileTbl(UreportFileTbl ureportFileTbl)
    {
        ureportFileTbl.setCreateTime(DateUtils.getNowDate());
        return ureportFileTblMapper.insertUreportFileTbl(ureportFileTbl);
    }

    /**
     * 修改报表管理
     *
     * @param ureportFileTbl 报表管理
     * @return 结果
     */
    @Override
    public int updateUreportFileTbl(UreportFileTbl ureportFileTbl)
    {
        ureportFileTbl.setUpdateTime(DateUtils.getNowDate());
        return ureportFileTblMapper.updateUreportFileTbl(ureportFileTbl);
    }

    /**
     * 批量删除报表管理
     *
     * @param ids 需要删除的报表管理主键
     * @return 结果
     */
    @Override
    public int deleteUreportFileTblByIds(Long[] ids)
    {
        return ureportFileTblMapper.deleteUreportFileTblByIds(ids);
    }

    /**
     * 删除报表管理信息
     *
     * @param id 报表管理主键
     * @return 结果
     */
    @Override
    public int deleteUreportFileTblById(Long id)
    {
        return ureportFileTblMapper.deleteUreportFileTblById(id);
    }

  private LambdaQueryWrapper<UreportFileTbl> buildQueryWrapper(UreportFileTbl bo) {
    Map<String, Object> params = bo.getParams();
    LambdaQueryWrapper<UreportFileTbl> lqw = Wrappers.lambdaQuery();
    lqw.eq(bo.getCreateDept() != null, UreportFileTbl::getCreateDept, bo.getCreateDept());
    return lqw;
  }
}
